<?php
require_once 'BaseMySQLDAO.php';

class GameMessageDAO extends BaseMySQLDAO {

    public function __construct($context) {
        parent::__construct($context, 'game_link');
    }
 
	public function getGameMessByIDTPG($id) {
        $result = array();
        try {
            $this -> getContext() -> getTransaction() -> startTransaction('thanhphogame');

            $inSQL = "	SELECT *
						FROM game_message
						WHERE id = :id
            		 ";
            $param = array(":id" => $id);
            
            $result = $this -> getContext() -> getTransaction() -> getMySQLConnection() -> loadOneRow($inSQL, $param);
            $this -> getContext() -> getTransaction() -> closeTransaction();
        } catch (Exception $exception) {
            $this -> getContext() -> logException($exception);
        }
        return $result;
    }
    
	public function getGameMessByIDCGMB($id) {
        $result = array();
        try {
            $this -> getContext() -> getTransaction() -> startTransaction('choigamemobi');

            $inSQL = "	SELECT *
						FROM game_message
						WHERE id = :id
            		 ";
            $param = array(":id" => $id);
            
            $result = $this -> getContext() -> getTransaction() -> getMySQLConnection() -> loadOneRow($inSQL, $param);
            $this -> getContext() -> getTransaction() -> closeTransaction();
        } catch (Exception $exception) {
            $this -> getContext() -> logException($exception);
        }
        return $result;
    }
    
	public function getGameMessByIDMMBG($id) {
        $result = array();
        try {
            $this -> getContext() -> getTransaction() -> startTransaction('mymobigame');

            $inSQL = "	SELECT *
						FROM game_message
						WHERE id = :id
            		 ";
            $param = array(":id" => $id);
            
            $result = $this -> getContext() -> getTransaction() -> getMySQLConnection() -> loadOneRow($inSQL, $param);
            $this -> getContext() -> getTransaction() -> closeTransaction();
        } catch (Exception $exception) {
            $this -> getContext() -> logException($exception);
        }
        return $result;
    }
    
	public function getGameMessByIDNSGT($id) {
        $result = array();
        try {
            $this -> getContext() -> getTransaction() -> startTransaction('ngoisaogamethu');

            $inSQL = "	SELECT *
						FROM game_message
						WHERE id = :id
            		 ";
            $param = array(":id" => $id);
            
            $result = $this -> getContext() -> getTransaction() -> getMySQLConnection() -> loadOneRow($inSQL, $param);
            $this -> getContext() -> getTransaction() -> closeTransaction();
        } catch (Exception $exception) {
            $this -> getContext() -> logException($exception);
        }
        return $result;
    }
    
	public function getAllGameMessByLimitTPG($start, $limit) {
        $result = array();
        try {
            $this -> getContext() -> getTransaction() -> startTransaction('thanhphogame');

            $inSQL = "	SELECT
							game_message.*, game_category.name as game_name
						FROM
							game_message, game_category
						WHERE game_message.game_category_id = game_category.id
						ORDER BY game_message.id DESC
            			LIMIT :start, :limit 
            		 ";
            $param = array(":start" => $start, ":limit" => $limit);
            $result = $this -> getContext() -> getTransaction() -> getMySQLConnection() -> loadManyRow($inSQL, $param);

            $this -> getContext() -> getTransaction() -> closeTransaction();
        } catch (Exception $exception) {
            $this -> getContext() -> logException($exception);
        }
        return $result;
    }
    
	public function getAllGameMessByLimitCGMB($start, $limit) {
        $result = array();
        try {
            $this -> getContext() -> getTransaction() -> startTransaction('choigamemobi');

            $inSQL = "	SELECT
							game_message.*, game_category.name as game_name
						FROM
							game_message, game_category
						WHERE game_message.game_category_id = game_category.id
						ORDER BY game_message.id DESC
            			LIMIT :start, :limit 
            		 ";
            $param = array(":start" => $start, ":limit" => $limit);
            $result = $this -> getContext() -> getTransaction() -> getMySQLConnection() -> loadManyRow($inSQL, $param);

            $this -> getContext() -> getTransaction() -> closeTransaction();
        } catch (Exception $exception) {
            $this -> getContext() -> logException($exception);
        }
        return $result;
    }
    
	public function getAllGameMessByLimitMMBG($start, $limit) {
        $result = array();
        try {
            $this -> getContext() -> getTransaction() -> startTransaction('mymobigame');

            $inSQL = "	SELECT
							game_message.*, game_category.name as game_name
						FROM
							game_message, game_category
						WHERE game_message.game_category_id = game_category.id
						ORDER BY game_message.id DESC
            			LIMIT :start, :limit 
            		 ";
            $param = array(":start" => $start, ":limit" => $limit);
            $result = $this -> getContext() -> getTransaction() -> getMySQLConnection() -> loadManyRow($inSQL, $param);

            $this -> getContext() -> getTransaction() -> closeTransaction();
        } catch (Exception $exception) {
            $this -> getContext() -> logException($exception);
        }
        return $result;
    }
    
	public function getAllGameMessByLimitNSGT($start, $limit) {
        $result = array();
        try {
            $this -> getContext() -> getTransaction() -> startTransaction('ngoisaogamethu');

            $inSQL = "	SELECT
							game_message.*, game_category.name as game_name
						FROM
							game_message, game_category
						WHERE game_message.game_category_id = game_category.id
						ORDER BY game_message.id DESC
            			LIMIT :start, :limit 
            		 ";
            $param = array(":start" => $start, ":limit" => $limit);
            $result = $this -> getContext() -> getTransaction() -> getMySQLConnection() -> loadManyRow($inSQL, $param);

            $this -> getContext() -> getTransaction() -> closeTransaction();
        } catch (Exception $exception) {
            $this -> getContext() -> logException($exception);
        }
        return $result;
    }
    
	public function countGameMessTPG() {
        $result = null;
        try {
            $this -> getContext() -> getTransaction() -> startTransaction('thanhphogame');

            $inSQL = "  SELECT count(id) as total FROM game_message ";
            
            $result = $this -> getContext() -> getTransaction() -> getMySQLConnection() -> loadOneRow($inSQL);

            $this -> getContext() -> getTransaction() -> closeTransaction();
        } catch (Exception $exception) {
            $this -> getContext() -> logException($exception);
        }
        return $result['total'];
    }
    
	public function countGameMessCGMB() {
        $result = null;
        try {
            $this -> getContext() -> getTransaction() -> startTransaction('choigamemobi');

            $inSQL = "  SELECT count(id) as total FROM game_message ";
            
            $result = $this -> getContext() -> getTransaction() -> getMySQLConnection() -> loadOneRow($inSQL);

            $this -> getContext() -> getTransaction() -> closeTransaction();
        } catch (Exception $exception) {
            $this -> getContext() -> logException($exception);
        }
        return $result['total'];
    }
    
	public function countGameMessMMBG() {
        $result = null;
        try {
            $this -> getContext() -> getTransaction() -> startTransaction('mymobigame');

            $inSQL = "  SELECT count(id) as total FROM game_message ";
            
            $result = $this -> getContext() -> getTransaction() -> getMySQLConnection() -> loadOneRow($inSQL);

            $this -> getContext() -> getTransaction() -> closeTransaction();
        } catch (Exception $exception) {
            $this -> getContext() -> logException($exception);
        }
        return $result['total'];
    }
    
	public function countGameMessNSGT() {
        $result = null;
        try {
            $this -> getContext() -> getTransaction() -> startTransaction('ngoisaogamethu');

            $inSQL = "  SELECT count(id) as total FROM game_message ";
            
            $result = $this -> getContext() -> getTransaction() -> getMySQLConnection() -> loadOneRow($inSQL);

            $this -> getContext() -> getTransaction() -> closeTransaction();
        } catch (Exception $exception) {
            $this -> getContext() -> logException($exception);
        }
        return $result['total'];
    }
    
	public function getAllGameMessByGameCateIDTPG($id) {
        $result = array();
        try {
            $this -> getContext() -> getTransaction() -> startTransaction('thanhphogame');

            $inSQL = "	SELECT game_message.*, game_category.name as game_name
						FROM game_message, game_category
						WHERE game_message.game_category_id = game_category.id
						AND game_message.game_category_id = :id
            		 ";
            $param = array(":id" => $id);
            $result = $this -> getContext() -> getTransaction() -> getMySQLConnection() -> loadManyRow($inSQL, $param);

            $this -> getContext() -> getTransaction() -> closeTransaction();
        } catch (Exception $exception) {
            $this -> getContext() -> logException($exception);
        }
        return $result;
    }
    
	public function getAllGameMessByGameCateIDCGMB($id) {
        $result = array();
        try {
            $this -> getContext() -> getTransaction() -> startTransaction('choigamemobi');

            $inSQL = "	SELECT game_message.*, game_category.name as game_name
						FROM game_message, game_category
						WHERE game_message.game_category_id = game_category.id
						AND game_message.game_category_id = :id
            		 ";
            $param = array(":id" => $id);
            $result = $this -> getContext() -> getTransaction() -> getMySQLConnection() -> loadManyRow($inSQL, $param);

            $this -> getContext() -> getTransaction() -> closeTransaction();
        } catch (Exception $exception) {
            $this -> getContext() -> logException($exception);
        }
        return $result;
    }
    
	public function getAllGameMessByGameCateIDMMBG($id) {
        $result = array();
        try {
            $this -> getContext() -> getTransaction() -> startTransaction('mymobigame');

            $inSQL = "	SELECT game_message.*, game_category.name as game_name
						FROM game_message, game_category
						WHERE game_message.game_category_id = game_category.id
						AND game_message.game_category_id = :id
            		 ";
            $param = array(":id" => $id);
            $result = $this -> getContext() -> getTransaction() -> getMySQLConnection() -> loadManyRow($inSQL, $param);

            $this -> getContext() -> getTransaction() -> closeTransaction();
        } catch (Exception $exception) {
            $this -> getContext() -> logException($exception);
        }
        return $result;
    }
    
	public function getAllGameMessByGameCateIDNSGT($id) {
        $result = array();
        try {
            $this -> getContext() -> getTransaction() -> startTransaction('ngoisaogamethu');

            $inSQL = "	SELECT game_message.*, game_category.name as game_name
						FROM game_message, game_category
						WHERE game_message.game_category_id = game_category.id
						AND game_message.game_category_id = :id
            		 ";
            $param = array(":id" => $id);
            $result = $this -> getContext() -> getTransaction() -> getMySQLConnection() -> loadManyRow($inSQL, $param);

            $this -> getContext() -> getTransaction() -> closeTransaction();
        } catch (Exception $exception) {
            $this -> getContext() -> logException($exception);
        }
        return $result;
    }
    
	public function insertGameMessage($param) {
        $result = null;
        try {
            $inSQL = "INSERT INTO
                        game_message(id, game_category_id, dau_so, cu_phap_dau, cu_phap_cuoi)
                        VALUES (
                            :id, :game_category_id, :dau_so, :cu_phap_dau, :cu_phap_cuoi
                        )";
            $queryParam = array(
                                ':id' => NULL,
                                ':game_category_id' => $param['game_category_id'],
                                ':dau_so' => $param['dau_so'],
                                ':cu_phap_dau' => $param['cu_phap_dau'],
                                ':cu_phap_cuoi' => $param['cu_phap_cuoi']
                            );
         
            $this -> getContext() -> getTransaction() -> startTransaction('thanhphogame');
            $this -> getContext() -> getTransaction() -> getMySQLConnection() -> executeNonQuery($inSQL, $queryParam);
            $this -> getContext() -> getTransaction() -> closeTransaction();
            
            $this -> getContext() -> getTransaction() -> startTransaction('mobile');
            $this -> getContext() -> getTransaction() -> getMySQLConnection() -> executeNonQuery($inSQL, $queryParam);
            $this -> getContext() -> getTransaction() -> closeTransaction();
            
            $this -> getContext() -> getTransaction() -> startTransaction('choigamemobi');
            $this -> getContext() -> getTransaction() -> getMySQLConnection() -> executeNonQuery($inSQL, $queryParam);
            $this -> getContext() -> getTransaction() -> closeTransaction();    
                        
            $this -> getContext() -> getTransaction() -> startTransaction('mymobigame');
            $this -> getContext() -> getTransaction() -> getMySQLConnection() -> executeNonQuery($inSQL, $queryParam);
            $this -> getContext() -> getTransaction() -> closeTransaction();
            
            $this -> getContext() -> getTransaction() -> startTransaction('ngoisaogamethu');
            $this -> getContext() -> getTransaction() -> getMySQLConnection() -> executeNonQuery($inSQL, $queryParam);
            $this -> getContext() -> getTransaction() -> closeTransaction();

        } catch (Exception $exception) {
            print_r($exception);
            exit;
        }
        return $result;
    }
    
	public function insertGameMessageMMBG($param) {
        $result = null;
        try {
            $inSQL = "INSERT INTO
                        game_message(id, game_category_id, dau_so, cu_phap_dau, cu_phap_cuoi)
                        VALUES (
                            :id, :game_category_id, :dau_so, :cu_phap_dau, :cu_phap_cuoi
                        )";
            $queryParam = array(
                                ':id' => NULL,
                                ':game_category_id' => $param['game_category_id'],
                                ':dau_so' => $param['dau_so'],
                                ':cu_phap_dau' => $param['cu_phap_dau'],
                                ':cu_phap_cuoi' => $param['cu_phap_cuoi']
                            );         
                        
            $this -> getContext() -> getTransaction() -> startTransaction('mymobigame');
            $this -> getContext() -> getTransaction() -> getMySQLConnection() -> executeNonQuery($inSQL, $queryParam);
            $this -> getContext() -> getTransaction() -> closeTransaction();

        } catch (Exception $exception) {
            print_r($exception);
            exit;
        }
        return $result;
    }
    
	public function updateGameMessageTPG($param) {
        $result = null;
        try {
            $inSQL = "	UPDATE game_message SET
                                    game_category_id = :game_category_id,
                                    dau_so = :dau_so,
                                    cu_phap_dau = :cu_phap_dau,
                                    cu_phap_cuoi = :cu_phap_cuoi
                        WHERE id = :id
            		";
            $queryParam = array(
                                ':id' => $param['id'],
                                ':game_category_id' => $param['game_category_id'],
                                ':dau_so' => $param['dau_so'],
                                ':cu_phap_dau' => $param['cu_phap_dau'],
                                ':cu_phap_cuoi' => $param['cu_phap_cuoi']
                            );
         
            $this -> getContext() -> getTransaction() -> startTransaction('thanhphogame');
            $this -> getContext() -> getTransaction() -> getMySQLConnection() -> executeNonQuery($inSQL, $queryParam);
            $this -> getContext() -> getTransaction() -> closeTransaction();  

            $this -> getContext() -> getTransaction() -> startTransaction('mobile');
            $this -> getContext() -> getTransaction() -> getMySQLConnection() -> executeNonQuery($inSQL, $queryParam);
            $this -> getContext() -> getTransaction() -> closeTransaction();

        } catch (Exception $exception) {
            print_r($exception);
            exit;
        }
        return $result;
    }
    
	public function updateGameMessageCGMB($param) {
        $result = null;
        try {
            $inSQL = "	UPDATE game_message SET
                                    game_category_id = :game_category_id,
                                    dau_so = :dau_so,
                                    cu_phap_dau = :cu_phap_dau,
                                    cu_phap_cuoi = :cu_phap_cuoi
                        WHERE id = :id
            		";
            $queryParam = array(
                                ':id' => $param['id'],
                                ':game_category_id' => $param['game_category_id'],
                                ':dau_so' => $param['dau_so'],
                                ':cu_phap_dau' => $param['cu_phap_dau'],
                                ':cu_phap_cuoi' => $param['cu_phap_cuoi']
                            );
            
            $this -> getContext() -> getTransaction() -> startTransaction('choigamemobi');
            $this -> getContext() -> getTransaction() -> getMySQLConnection() -> executeNonQuery($inSQL, $queryParam);
            $this -> getContext() -> getTransaction() -> closeTransaction();

        } catch (Exception $exception) {
            print_r($exception);
            exit;
        }
        return $result;
    }
    
	public function updateGameMessageMMBG($param) {
        $result = null;
        try {
            $inSQL = "	UPDATE game_message SET
                                    game_category_id = :game_category_id,
                                    dau_so = :dau_so,
                                    cu_phap_dau = :cu_phap_dau,
                                    cu_phap_cuoi = :cu_phap_cuoi
                        WHERE id = :id
            		";
            $queryParam = array(
                                ':id' => $param['id'],
                                ':game_category_id' => $param['game_category_id'],
                                ':dau_so' => $param['dau_so'],
                                ':cu_phap_dau' => $param['cu_phap_dau'],
                                ':cu_phap_cuoi' => $param['cu_phap_cuoi']
                            );
         
            $this -> getContext() -> getTransaction() -> startTransaction('mymobigame');
            $this -> getContext() -> getTransaction() -> getMySQLConnection() -> executeNonQuery($inSQL, $queryParam);
            $this -> getContext() -> getTransaction() -> closeTransaction();

        } catch (Exception $exception) {
            print_r($exception);
            exit;
        }
        return $result;
    }
    
	public function updateGameMessageNSGT($param) {
        $result = null;
        try {
            $inSQL = "	UPDATE game_message SET
                                    game_category_id = :game_category_id,
                                    dau_so = :dau_so,
                                    cu_phap_dau = :cu_phap_dau,
                                    cu_phap_cuoi = :cu_phap_cuoi
                        WHERE id = :id
            		";
            $queryParam = array(
                                ':id' => $param['id'],
                                ':game_category_id' => $param['game_category_id'],
                                ':dau_so' => $param['dau_so'],
                                ':cu_phap_dau' => $param['cu_phap_dau'],
                                ':cu_phap_cuoi' => $param['cu_phap_cuoi']
                            );
            
            $this -> getContext() -> getTransaction() -> startTransaction('ngoisaogamethu');
            $this -> getContext() -> getTransaction() -> getMySQLConnection() -> executeNonQuery($inSQL, $queryParam);
            $this -> getContext() -> getTransaction() -> closeTransaction();

        } catch (Exception $exception) {
            print_r($exception);
            exit;
        }
        return $result;
    }
    
 	public function deleteGameMessageTPG($id) {
        try {

            $inSQL = "   DELETE FROM game_message WHERE id = :id ";
            $param = array(':id' => $id);

            $this -> getContext() -> getTransaction() -> startTransaction('thanhphogame');
            $this -> getContext() -> getTransaction() -> getMySQLConnection() -> executeNonQuery($inSQL, $param);
            $this -> getContext() -> getTransaction() -> closeTransaction();
            
            $this -> getContext() -> getTransaction() -> startTransaction('mobile');
            $this -> getContext() -> getTransaction() -> getMySQLConnection() -> executeNonQuery($inSQL, $param);
            $this -> getContext() -> getTransaction() -> closeTransaction();
        } catch (Exception $exception) {
            $this -> getContext() -> logException($exception);
            return false;
        }
        return true;
    }
    
	public function deleteGameMessageCGMB($id) {
        try {

            $inSQL = "   DELETE FROM game_message WHERE id = :id ";
            $param = array(':id' => $id);

            $this -> getContext() -> getTransaction() -> startTransaction('choigamemobi');
            $this -> getContext() -> getTransaction() -> getMySQLConnection() -> executeNonQuery($inSQL, $param);
            $this -> getContext() -> getTransaction() -> closeTransaction();
        } catch (Exception $exception) {
            $this -> getContext() -> logException($exception);
            return false;
        }
        return true;
    }
    
	public function deleteGameMessageMMBG($id) {
        try {

            $inSQL = "   DELETE FROM game_message WHERE id = :id ";
            $param = array(':id' => $id);

            $this -> getContext() -> getTransaction() -> startTransaction('mymobigame');
            $this -> getContext() -> getTransaction() -> getMySQLConnection() -> executeNonQuery($inSQL, $param);
            $this -> getContext() -> getTransaction() -> closeTransaction();
        } catch (Exception $exception) {
            $this -> getContext() -> logException($exception);
            return false;
        }
        return true;
    }
    
	public function deleteGameMessageNSGT($id) {
        try {

            $inSQL = "   DELETE FROM game_message WHERE id = :id ";
            $param = array(':id' => $id);

            $this -> getContext() -> getTransaction() -> startTransaction('ngoisaogamethu');
            $this -> getContext() -> getTransaction() -> getMySQLConnection() -> executeNonQuery($inSQL, $param);
            $this -> getContext() -> getTransaction() -> closeTransaction();
        } catch (Exception $exception) {
            $this -> getContext() -> logException($exception);
            return false;
        }
        return true;
    }
    
}
?>